package com.choudou5.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSON;

/**
 * @Name：日志调试 工具类
 * @@author choudou5
 * @@date 2018-07-17
 */
public class LogUtil {

    private static final String LOG_SPLIT = "__";
    private static boolean needEnableLogger = true;

    public static void setNeedEnableLogger(boolean needEnableLogger) {
        LogUtil.needEnableLogger = needEnableLogger;
    }

    public static void debug(Object ... params) {
        if (!needEnableLogger) {
            return;
        }
        StringBuilder sb = new StringBuilder(32);
        sb.append(DateUtil.now());// 时间
        if(ArrayUtil.isNotEmpty(params)){
            for (Object param : params) {
                sb.append(LOG_SPLIT);
                if(param instanceof String)
                    sb.append(param);
                else
                    sb.append(JSON.toJSONString(param));
            }
        }
        System.out.println(sb.toString());
    }


    public static void error(String msg, Exception e) {
        System.out.println(msg+""+e.getMessage());
        e.printStackTrace();
    }

}
